﻿using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using WPFExcelReport.Helpers;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    public partial class UIVV : ViewBase
    { 
        public UIVV()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
        }
        public void ResetSeq(object sender, RoutedEventArgs e)
        {
            if (!TMV.IsITX)
            {
                return;
            }
            VSDDAT.SD22.RESETSEQ("0022", KRS, "VLIEFSCH", "1");
            dwData = TBMain.NewRow();
            dwData["VVMANDANT"] = app.Mandant; 
            TMV.DeleteVVLIEF(dwData, 0);
            
            dwData = TMV.VVT.TBMain.NewRow();
            dwData["VVTMANDANT"] = app.Mandant; 
            TMV.VVT.DeleteVVTLIEF(dwData, 2); 
        }
        public override void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            if (IsLoaded)
                return;
            base.Window_Loaded(sender, e);
        }

        public override void vwMaster_CurrentChanged(object sender, System.EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwVV = dwMaster;
            
        }

        public override void OnWorkflowIDChange(MessageEventArgs e)
        {
            base.OnWorkflowIDChange(e);
            MessageInfo msg = e.Info;
            string task = msg.MSGTYPE;
            switch (task)
            { 
                case "WB2KO":
                    WB2KO(msg);
                    break;
                case "VVCHG":
                    break;
            }
        }

        double LINE = 0;
        public void WB2KO(MessageInfo msg)
        {
            dwData = TBMain.NewRow();
            dwData["VVMANDANT"] = app.Mandant;
            dwData["VVLIEFSCH"] = msg.LIEFSCH;
            SResult = ((VVVLIEF)MV).QueryVVLIEF(dwData, 1);
            MergeData(SResult, true);
        }  
       

        public virtual void OnVKPChg(string vkp)
        {
            if (vkp.Length < 1)
            {
                VKADR = "";
                return;
            }
            VKADR = vkp.Substring(1, 11) + LIEFSCH.PadRight(8) + vkp.Substring(0, 1);
        }
        public virtual void OnVKADRChg(string vkp)
        {
        }
        public virtual void OnVVTChg(string vvt)
        {

        }
        public virtual void OnVVISChg(string vvt)
        {

        }
        public virtual void OnSARTChg(string value)
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            ((VVVLIEF)MV).VVVERSART = value;
        }
        public virtual void OnVSPEDChg(string value)
        {
            if (!IsEdit)
                return;
            if (dwMaster == null)
                return;
            ((VVVLIEF)MV).VVSPED = value;
        }
    }
    public partial class UIVV : ViewBase
    {
        public VVVLIEF TMV
        {
            get
            {
                return (VVVLIEF)MV;
            }
        }
        #region ==SART===========
        public static readonly DependencyProperty SARTProperty = DependencyProperty.Register("SART",
            typeof(string), typeof(UIVV),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSARTChanged));
        public string SART
        {
            get
            {
                return (string)GetValue(SARTProperty);
            }
            set
            {
                SetValue(SARTProperty, value);
                OnSARTChg(value);
            }
        }
        private static void OnSARTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVV;
            if (src != null)
            {
                src.SART = (string)e.NewValue;
            }
        }
        #endregion

        #region ==VSPED===========
        public static readonly DependencyProperty VSPEDProperty = DependencyProperty.Register("VSPED",
            typeof(string), typeof(UIVV),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVSPEDChanged));
        public string VSPED
        {
            get
            {
                return (string)GetValue(VSPEDProperty);
            }
            set
            {
                SetValue(VSPEDProperty, value);
                OnVSPEDChg(value);
            }
        }
        private static void OnVSPEDChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVV;
            if (src != null)
            {
                src.VSPED = (string)e.NewValue;
            }
        }
        #endregion


        #region ==LIEFSCH===========
        public static readonly DependencyProperty LIEFSCHProperty = DependencyProperty.Register("LIEFSCH",
            typeof(string), typeof(UIVV),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnLIEFSCHChanged));
        public string LIEFSCH
        {
            get
            {
                return (string)GetValue(LIEFSCHProperty);
            }
            set
            {
                SetValue(LIEFSCHProperty, value);
                ORDERNUM = LIEFSCH;
            }
        }
        private static void OnLIEFSCHChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVV;
            if (src != null)
            {
                src.LIEFSCH = (string)e.NewValue;
            }
        }
        #endregion

        #region ==dwVV===========
        public static readonly DependencyProperty dwVVProperty = DependencyProperty.Register("dwVV",
            typeof(DataRow), typeof(UIVV),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwVVChanged));
        public DataRow dwVV
        {
            get
            {
                return (DataRow)GetValue(dwVVProperty);
            }
            set
            {
                SetValue(dwVVProperty, value);
            }
        }
        private static void OndwVVChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVV;
            if (src != null)
            {
                src.dwVV = (DataRow)e.NewValue;
            }
        }
        #endregion

        #region ==dwVKP===========
        public static readonly DependencyProperty dwVKPProperty = DependencyProperty.Register("dwVKP",
            typeof(DataRow), typeof(UIVV),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwVKPChanged));
        public DataRow dwVKP
        {
            get
            {
                return (DataRow)GetValue(dwVKPProperty);
            }
            set
            {
                SetValue(dwVKPProperty, value);
            }
        }
        private static void OndwVKPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVV;
            if (src != null)
            {
                src.dwVKP = (DataRow)e.NewValue;
            }
        }
        #endregion

        #region ==dwVKK===========
        public static readonly DependencyProperty dwVKKProperty = DependencyProperty.Register("dwVKK",
            typeof(DataRow), typeof(UIVV),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwVKKChanged));
        public DataRow dwVKK
        {
            get
            {
                return (DataRow)GetValue(dwVKKProperty);
            }
            set
            {
                SetValue(dwVKKProperty, value);
            }
        }
        private static void OndwVKKChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVV;
            if (src != null)
            {
                src.dwVKK = (DataRow)e.NewValue;
            }
        }
        #endregion

        #region ==VKP===========
        public static readonly DependencyProperty VKPProperty = DependencyProperty.Register("VKP",
            typeof(string), typeof(UIVV),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVKPChanged));
        public string VKP
        {
            get
            {
                return (string)GetValue(VKPProperty);
            }
            set
            {
                SetValue(VKPProperty, value);
                OnVKPChg(value);
            }
        }
        private static void OnVKPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVV;
            if (src != null)
            {
                src.VKP = (string)e.NewValue;
            }
        }
        #endregion

        #region ==dwKDR===========
        public static readonly DependencyProperty dwKDRProperty = DependencyProperty.Register("dwKDR",
            typeof(DataRow), typeof(UIVV),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OdwKDRChanged));
        public DataRow dwKDR
        {
            get
            {
                return (DataRow)GetValue(dwKDRProperty);
            }
            set
            {
                SetValue(dwKDRProperty, value);
            }
        }
        private static void OdwKDRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVV;
            if (src != null)
            {
                DataRow row = (DataRow)e.NewValue;
                src.dwKDR = row;
            }
        }
        #endregion

        #region ==dwVKVV===========
        public static readonly DependencyProperty dwVKVVProperty = DependencyProperty.Register("dwVKVV",
            typeof(DataRow), typeof(UIVV),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OdwVKVVChanged));
        public DataRow dwVKVV
        {
            get
            {
                return (DataRow)GetValue(dwVKVVProperty);
            }
            set
            {
                SetValue(dwVKVVProperty, value);
            }
        }
        private static void OdwVKVVChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVV;
            if (src != null)
            {
                DataRow row = (DataRow)e.NewValue;
                src.dwVKVV = row;
            }
        }
        #endregion

        #region ==VKADR===========
        public static readonly DependencyProperty VKADRProperty = DependencyProperty.Register("VKADR",
            typeof(string), typeof(UIVV),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVKADRChanged));
        public string VKADR
        {
            get
            {
                return (string)GetValue(VKADRProperty);
            }
            set
            {
                SetValue(VKADRProperty, value);
                OnVKADRChg(value);
            }
        }
        private static void OnVKADRChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVV;
            if (src != null)
            {
                src.VKADR = (string)e.NewValue;
            }
        }
        #endregion

        #region ==VVT===========
        public static readonly DependencyProperty VVTProperty = DependencyProperty.Register("VVT",
            typeof(string), typeof(UIVV),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVVTChanged));
        public string VVT
        {
            get
            {
                return (string)GetValue(VVTProperty);
            }
            set
            {
                SetValue(VVTProperty, value);
                OnVVTChg(value);
            }
        }
        private static void OnVVTChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVV;
            if (src != null)
            {
                src.VVT = (string)e.NewValue;
            }
        }
        #endregion
        #region ==VVIS===========
        public static readonly DependencyProperty VVISProperty = DependencyProperty.Register("VVIS",
            typeof(string), typeof(UIVV),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnVVISChanged));
        public string VVIS
        {
            get
            {
                return (string)GetValue(VVISProperty);
            }
            set
            {
                SetValue(VVISProperty, value);
                OnVVISChg(value);
            }
        }
        private static void OnVVISChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIVV;
            if (src != null)
            {
                src.VVIS = (string)e.NewValue;
            }
        }
        #endregion
    }
}